package com.musemun.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.musemun.mapper.CrifoMapper;
import com.musemun.pojo.Crifo;
import com.musemun.service.CrifoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.musemun.service.CropifoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author winner
 * @since 2020-04-27
 */
@Service
public class CrifoServiceImpl extends ServiceImpl<CrifoMapper, Crifo> implements CrifoService {
    @Resource
    CropifoService cropifoService;
    //只在excelListener中使用，不然会造成多线程异常
    Logger log = LoggerFactory.getLogger(CrifoServiceImpl.class);

    public List<Crifo> list= new CopyOnWriteArrayList<>();

    /**
     *调用父类方法录入数据库录入数据库功能
     * @return void
     */
    public List<Crifo> readList(){
        super.updateBatchById(list);

        log.info("读入数据库成功");
        return list;
    }

    public boolean addList(List<Crifo> dataList){
        log.info("加入list成功");
        return list.addAll(dataList);
//        return list.addAll(dataList);
    }

    /**
     *
     *
     * @param index 0为查询所有，1为查询需要入库的，2为查询所有已经入库的
     * @return java.util.List<com.musemun.pojo.Crifo>
     */
    @Override
    public List<Crifo> ByIndexQuery(int index) {
        List<Crifo>crifoList=new ArrayList<>();
        switch (index){
            case 0:
                crifoList=list(new QueryWrapper<>());
                break;
            case 1:
                crifoList = list(new QueryWrapper<Crifo>().and(data->data.isNotNull("crPic").eq("crState","在馆")));
                break;
            case 2:
                crifoList= list(new QueryWrapper<Crifo>().and(data->data.isNotNull("crPic").eq("crState","入库")));
                break;
        }
        return crifoList;
    }


}
